--从网页自动拉取数据填充params 写mysql 写邮件 资源上传


print("input offerid:")
local offerid = io.read("*num")
if offerid then

	local pfile = io.open("params" .. offerid .. ".lua", 'r')
	 
	if pfile then
		local str = pfile:read("*all")
		local params = loadstring(str)()
		
		params.offerID = params.offerID or offerid

		params.oid = params.offerID - 100000
		params.cid = params.campaignID - 100000

		--转义特殊字符 sql语句格式
		for key, v in pairs(params) do
			params[key] = string.gsub(v,"\'","\\\'")
			params[key] = string.gsub(params[key],"%%","%%%%") 
			--mysql语句不需要转义%  主要防止在lua的模式匹配函数中%转义别的字符如kpi="rate>40%", 会出错 
		end

		local f = io.open("lib_offer.sql", 'r')
		local lib_offer = f:read("*all")
		f:close()
		for key, v in pairs(params) do
			lib_offer = string.gsub(lib_offer,"XXX" .. key .. "XXX",v)
		end

		local f = io.open("lib_campaign.sql", 'r')
		local lib_campaign = f:read("*all")
		f:close()
		for key, v in pairs(params) do
			lib_campaign = string.gsub(lib_campaign,"XXX" .. key .. "XXX",v)
		end

		local f = io.open("interface_info_v1.sql", 'r')
		local interface_info_v1 = f:read("*all")
		f:close()
		for key, v in pairs(params) do
			interface_info_v1 = string.gsub(interface_info_v1,"XXX" .. key .. "XXX",v)
		end
		print(lib_offer .. "\n\n" .. lib_campaign .. "\n\n" .. interface_info_v1 .. "\n\n")
		require"luasql.mysql"
		env=luasql.mysql()
		conn=env:connect("ad688com","ad688com","ad688com","rdsea0aj9n7m3g48ta5u.mysql.rds.aliyuncs.com",3306)
		conn:execute"SET NAMES GB2312"
		
		cur=conn:execute(lib_offer)
		if cur then print("write lib_offer success") end
		
		cur=conn:execute(lib_campaign)
		if cur then print("write lib_campaign success") end
		
		cur=conn:execute(interface_info_v1)
		if cur then print("write interface_info_v1 success") end

		conn:close()	
		env:close()   
	else

		print("invalid offerid")
	end

	local s = io.read("*all")
end





